﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using ScrappyDB.Attributes;
using ScrappyDB.BaseClasses;

namespace ScrappyDB.IntegrationTests.Core
{
    [TestFixture]
    public class PagingTest
    {
        [TestFixtureSetUp]
        public  void Init()
        {
            var a = new SdbCollection<TestItem>();

            for (int x = 0; x < 100; x++)
            {
                a.Add(new TestItem() { Id = x, TestString = "test" + x.ToString() });
            }

            a.SaveChanges();
        }

        [TestFixtureTearDown]
        public static void MyClassCleanup()
        {
            var db = new Db();
            var b = db.Query<TestItem>(null, true);
            db.Delete(b);
        }

        class TestItemContext : ScrappyDB.Linq.SdbContext
        {
            public ScrappyDB.Linq.SdbSet<TestItem> TestItems { get; set; }
        }

        [DomainName("ScrappyDB_UnitTests"), EntityName("PagingTest_TestItem")]
        class TestItem
        {
            public int Id { get; set; }
            public string TestString { get; set; }
        }

        [Test]
        public void BasicPaging()
        {
            //var context = new TestItemContext();
            //var b = (from t in context.TestItems where t.Id >= 0 orderby t.Id select t).Skip(50).Take(10).ToList();
            var db = new Db();
            var b = db.Query<TestItem>(null, null, 50, 10, true);

            Assert.AreEqual(10, b.Count);
            Assert.AreEqual(50, b.First().Id);
        }
    }
}
